package com.zpark.rabbitmq.subject_pattern;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.zpark.rabbitmq.config.ConnectionUtil;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @PackageName: com.zpark.rabbitmq.subject_pattern
 * @ClassName: Producer
 * @Description:
 * @author: RZS
 * @date: 2022/12/13  17:18
 */
public class Producer {

    private static final String EXCHANGE_NAME = "test_exchange_topic";

    public static void main(String[] args) throws IOException, TimeoutException {
        Connection conn = ConnectionUtil.getConnection();
        Channel channel = conn.createChannel();
        // 声明交换机
        channel.exchangeDeclare(EXCHANGE_NAME, "topic", true);
        // 发送100条消息
        for(int i=0; i<100; i++) {
            String msg = "Hello World! " + i;
            channel.basicPublish(EXCHANGE_NAME, "topic.1.23.456", null, msg.getBytes());
            System.out.println("生产者： 发送了 msg -- > " + msg);
        }
        channel.close();
        conn.close();
    }
}
